package org.adoxx.adows.client.main; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Properties; import javax.xml.rpc.ServiceException; import org.adoxx.adows.client.ADOxxWebService; import org.apache.axis.encoding.Base64; import com.boc_eu.adoweb.adows.adoscript.GetModelImage; /** * @author wutz * * Sample implementation to retreive the model image of a model. * * FIXME: the return XML is currently available as a XML in String * format, in case further steps are needed, parsing of the return needs * to be implemented. * * FIXME: the modelid is hard-coded and needs to be dynamically * retrieved from TOC interaction * * FIXME: the return is a stream and for the demonstration written to a * temp file. The returned stream is a base64 encoded string * representation of the image * */ public class RunADOxxServiceInteractionModelImage { public static void main(String[] args) throws ServiceException, IOException { // load property for endpoint reference Properties prop = new Properties(); InputStream inputStream = RunADOxxServiceInteractionModelDocuXML.class.getClassLoader().getResourceAsStream("config.properties"); prop.load(inputStream); // Construct the ADOxx service as a singleton in the application. ADOxxWebService service = ADOxxWebService.getInstance(prop.getProperty("endpoint")); // Create the interaction object, using the service, the modelid and a // boolean if record rows should be included as an input, // implictly triggers the service interaction, the returned XML is in // accordance with the schema available here // http://www.adoxx.org/AdoScriptDoc/files/Message_Ports/Component_APIs/Documentation/XML_MODEL_DOCU-js.html#XML_MODEL_DOCU String imageFormat = "bmp"; // possible formats are: bmp, gif, ico, // jpeg, png, targa, tiff, wbmp, xpm GetModelImage modelGfx = new GetModelImage(service, 11201, imageFormat, 1.00); // Handle the results - get temp file File temp = File.createTempFile("model_image_" + String.valueOf(11201), "." + imageFormat); byte[] imageData = Base64.decode(modelGfx.getResult()); // write byte to file FileOutputStream out = new FileOutputStream(temp); out.write(imageData); out.close(); // return the file location System.out.println("Image file written to : " + temp.getAbsolutePath()); } }